<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            padding: 0;
            margin: 0;
            list-style: none;
            display: flex;
        }

        li {
            width: 100px;
            text-align: center;
            line-height: 30px;
            border: 1px solid #000;
            margin: 10px;
        }
    </style>
</head>

<body>

    <ul>
        <li id="a">11</li>
        <li id="b">22</li>
        <li id="c">33</li>
        <li id="d">44</li>
    </ul>

    <script>

        // 单选

        var oLis = document.querySelectorAll('ul li');
        // console.log(oLis);

        // 循环绑定事件
        for (var i = 0; i < oLis.length; i++) {
            // console.log(11111111111);
            oLis[i].onclick = function () {
                // alert('我是测试');
                console.log(i);

                // 先把所有的变黑，再把当前这个变红
                for (var i = 0; i < oLis.length; i++) {
                    oLis[i].style.color = '#000';
                }

                this.style.color = 'red';

            }
        }

    </script>

</body>

</html>